package com.coffee.wx.uitls;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

/**
 * 获取 Access token
 */
public class TokenUtils {
    private static final String APP_ID = "wx1679fc8e56c3f821";
    private static final String APP_SECRET = "ee6f4b9af98d70cee1b7a72a15af5117";

    private static final String URL = "https://api.weixin.qq.com/cgi-bin/token";

    public static final String PARAM = "grant_type=client_credential&appid=%s&secret=%s";

    /**
     * 获取token
     *
     * @return
     */
    public static String getToken() {

        String paramStr = String.format(PARAM, APP_ID, APP_SECRET);

        return SendHttpUtils.doGet(URL, paramStr);

    }

    public static String getAccessToken() {
        String token = getToken();
        JSONObject entries = JSONUtil.parseObj(token);
        return entries.getStr("access_token");
    }
}
